package com.hzmg.route;

import akka.http.javadsl.model.HttpRequest;
import akka.http.javadsl.model.Uri;
import com.hzmg.filter.FilterDefinition;
import com.hzmg.handler.PredicateDefinition;
import org.springframework.validation.annotation.Validated;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.*;


/**
 * 路由定义
 *
 *
 */
@Validated
public class RouteDefinition implements Shift {
    @NotEmpty
    private String id;

    @NotEmpty
    @Valid
    private List<PredicateDefinition> predicates = new ArrayList<>();

    @Valid
    private List<FilterDefinition> filters = new ArrayList<>();

    @NotNull
    private Uri uri;

    private HttpRequest request;

    private AkkaRequestEntity requestEntity;

    private int order = 0;

    public RouteDefinition() {
    }

    public RouteDefinition(Uri uri) {
        this.uri = uri;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public List<PredicateDefinition> getPredicates() {
        return predicates;
    }

    public void setPredicates(List<PredicateDefinition> predicates) {
        this.predicates = predicates;
    }

    public List<FilterDefinition> getFilters() {
        return filters;
    }

    public void setFilters(List<FilterDefinition> filters) {
        this.filters = filters;
    }

    public Uri getUri() {
        return uri;
    }

    public void setUri(Uri uri) {
        this.uri = uri;
    }

    public int getOrder() {
        return order;
    }

    public void setOrder(int order) {
        this.order = order;
    }

    public HttpRequest getRequest() {
        return request;
    }

    public void setRequest(HttpRequest request) {
        this.request = request;
    }

    public AkkaRequestEntity getRequestEntity() {
        return requestEntity;
    }

    public void setRequestEntity(AkkaRequestEntity requestEntity) {
        this.requestEntity = requestEntity;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        RouteDefinition that = (RouteDefinition) o;
        return this.order == that.order && Objects.equals(this.id, that.id)
                && Objects.equals(this.predicates, that.predicates)
                && Objects.equals(this.filters, that.filters)
                && Objects.equals(this.uri, that.uri);
    }

    @Override
    public int hashCode() {
        return Objects.hash(this.id, this.predicates, this.filters, this.uri,
                this.order);
    }

    @Override
    public String toString() {
        return "RouteDefinition{" + "id='" + id + '\'' + ", predicates=" + predicates
                + ", filters=" + filters + ", uri=" + uri + ", order=" + order + '}';
    }
}
